<template>
      <div>
        关注商品列表：
        <Checkbox :datas="goods" v-model="good_value"></Checkbox>
        <br><br>
        <Button @click="flow" color="green">取关</Button>
      </div>
</template>

<script>
    export default {
        name: "uidflows",
      data(){
          return{
            //商品所有关注列表
            goods:[],
            // 商品单个选中
            good_value:[],
            myid:'',
          }
      },
      mounted:function(){
          //调用接口
          this.get_goods();


      },
      methods:{
          //批量操作
          flow:function(){
            console.log(this.good_value);

            var goods = [];
            for(let i=0, l=this.good_value.length; i<l; i++){
                  goods.push(this.myid[this.good_value[i]]);
                }

            //转换成字符串
            var glist = JSON.stringify(goods);
            console.log(glist);

            this.axios.get('http://127.0.0.1:8000/getflow/',
              {params: {uid: localStorage.getItem('uid'), ids:glist, type:2
              }}).then(res=>{
              console.log(res);
              this.$Message(res.data.msg);
            })
          },


          //获取关注商品
          get_goods:function() {
            this.axios.get('http://127.0.0.1:8000/uidflow/',
              {
                params: {
                  uid: localStorage.getItem('uid')
                }
              }).then(res => {
              console.log(res);

              var goods = [];
              for (let i = 0, l = res.data.length; i < l; i++) {
                goods.push(res.data[i].name);
                this.myid[res.data[i].name] = res.data[i].id;
              }

              //赋值
              this.goods = goods;
              this.good_value = goods;
              console.log(goods)
            })
          }
      }
    }
</script>

<style scoped>

</style>
